const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');

module.exports = {
    entry: {
        common: ['react', 'react-dom', 'redux', 'react-redux',
            'redux-thunk', 'react-router', 'rc-animate',
            'event-emitter', 'seamless-immutable', 'react-bootstrap'
        ],
        main: './src/main.tsx',
    },
    output: {
        path: __dirname + '/dist',
        filename: '[name].js'
    },

    // Enable sourcemaps for debugging webpack's output.
    // devtool: 'source-map',

    resolve: {
        extensions: ['', '.js', '.jsx', '.ts', '.tsx'],
        root: __dirname,
        alias: {}
    },

    module: {
        loaders: [{
            test: /\.tsx?$/,
            loader: 'ts-loader'
        }, {
            test: /\.less$/,
            loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader')
        }, {
            test: /\.(png|jpg|gif)$/,
            loader: 'url-loader',
            query: {
                limit: 1024 * 1024,
                name: '[path][name].[ext]'
            }
        }, {
            test: /\.(woff|svg|eot|ttf)\??.*$/,
            loader: 'url-loader'
        }, {
            test: /\.(htm|html)$/i,
            loader: 'html-withimg-loader'
        }, {
            test: /\.css$/,
            loader: 'style-loader!css-loader'
        }],
        preLoaders: [
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            { test: /\.js?$/, loader: 'source-map-loader' }
        ]
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin('common.js'),
        new webpack.NoErrorsPlugin(),
        new ExtractTextPlugin('[name].css')
    ],
    ts: {
        configFileName: 'tsconfig.json'
    },
    tslint: {
        configuration: require('./tslint.json')
    }
};